<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><{$Think.config.cfg_webname}></title>
    <link href="__CSS__/base.css" rel="stylesheet">
    <link href="__CSS__/school.css" rel="stylesheet">
    <link rel="stylesheet" href="__PUBLIC__/custom/uimaker/easyui.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/custom/uimaker/icon.css">
    <style>
    #formAdd table{ width:100%;}
    #formAdd table td{ padding:5px;}
    #formAdd table td.td-left{text-align: right; padding-right: 10px;}
    </style>

</head>
<body>
<div class="container">
    <table id="dg"></table>
</div>
<div class="container">
    <table id="cxdm"></table>
    <div id="tb" style="padding:0 30px;">
        <div id="toolbar">
            <!--<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editGame()">修改</a>-->
            <!--<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="delGame()">删除</a>-->
            <input id="searchcont" name="search" value="" placeholder="请输入.." style="width: 200px;height: 28px;">
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="searchGame()">搜索</a><hr style="border: 1px solid #ddd;" />
        </div>
    </div>
</div>

<div class="container">
    <div id="DivAdd" class="easyui-dialog" style="width:450px;padding:10px 20px"
         closed="true" resizable="true" modal="true" data-options="iconCls: 'icon-edit',buttons: '#dlg-buttons'">
        <form id="formAdd" method="post" novalidate="novalidate">
            <input type="hidden" id="action" name="action">
            <input type="hidden" id="uid" name="uid">
            <table>
                <tr>
                    <td class="td-left" width="25%">用户名:</td>
                    <td width="75%"><input class="easyui-textbox" type="text" name="username" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">统用金币数量:</td>
                    <td width="75%"><input class="easyui-textbox" type="text" name="gold" data-options="required:true" style="height:30px;"></td>
                </tr>
            </table>
        </form>
    </div>
    <div id="dlg-buttons">
        <div style="text-align:right;">
            <a href="javascript:void(0)" class="easyui-linkbutton" id="btnAddOK" iconcls="icon-ok" onclick="btnAddOK()">确定</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#DivAdd').dialog('close')">关闭</a>
        </div>
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/custom/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/custom/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/custom/easyui-lang-zh_CN.js"></script>


<script type="text/javascript">
    $(function(){
        index();
    });

    function index(){
        //加载数据
        var search = Trim($('#searchcont').val());
        $('#cxdm').datagrid({
            title:'用户管理',
            width:'100%',
            height:$(window).height(),
            fitColumns:true,
            striped: true,
            checkOnSelect:true,
            singleSelect : false,
            queryParams:{
                search:search
            },
            // frozenColumns:[[//在冻结列中加入多选框
            //     {field:'chek',checkbox:true}
            // ]],
            url:'<{:U("Users/usersList")}>',
            loadMsg:'数据加载中请稍后……',
            pagination: true,
            rownumbers: false,
            pageList:[10, 15, 20,30],
            pageSize:15,
            toolbar:'#tb',
            columns:[[
                {field:'uid',title: 'ID',align: 'center',sortable:"true",width:30},
                {field:'username',title: '用户名',align: 'center',width:100,},
                {field:'orange',title: 'orange',align: 'center',width:100,},
                {field:'createtime',title: '创建时间',align: 'center',width:100,
                    formatter:function(val,row,index){
                        return RiQi(val);
                    }
                },
            ]],
        });
    }

    function addGame(){
        $("#DivAdd").dialog('open').dialog('setTitle', '新增App');
        $('#formAdd').form('clear');
        $('#action').val("add");
    }

    function editGame(id){
        var arr=$('#cxdm').datagrid('getSelections');
        if(!arr[0]){
            $.messager.alert('提示','请选择一条数据!');
            return false;
        }
        console.log(arr[0]);
        $("#DivAdd").dialog('open').dialog('setTitle', '修改用户信息');
        $('#formAdd').form('load',arr[0]);
        $('#action').val("update");

    }

    function Trim(str)
    { 
      return str.replace(/(^\s*)|(\s*$)/g, ""); 
    }

    function searchGame(){
        index();
    }

    function delGame() {
        var selRow = $('#cxdm').datagrid('getSelections');
        if (selRow.length == 0) {
            $.messager.alert("提示", "请选择要删除的行！", "info");
            return;
        } else {
            var array = new Array();
            for (var i = 0; i < selRow.length; i++) {

                array[i] = selRow[i]['uid'];

            }

            $.messager.confirm('提示', '确定删除?', function (r) {
                if (r) {
                    $.ajax({
                        type: "POST",
                        url: '<{:U("Users/delUsers")}>',
                        data:{id:array},
                        success: function (result) {
                            if (result.status == 1) {
                                $('#cxdm').datagrid('clearSelections');
                                $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                $('#cxdm').datagrid('reload');
                            } else {
                                $.messager.alert("提示", "删除失败，请重新操作！", "info");
                                return;
                            }
                        }
                    })
                }
            });
        }
    }


    function reload(){
        window.location.reload();
    }

    function btnAddOK() {
        $('#formAdd').form('submit',{
            url: '<{:U("Users/editUsers")}>',
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                if (result.success){
                        $.messager.alert('提示','修改成功!','info',function(){
                            reload();
                        });
                } else {
                    $.messager.show({
                        title: '错误提示',
                        msg: result.msg
                    });
                }
            }
        });
    }

    function RiQi(sj) {
        var   now = new Date(sj*1000);
        var   year=now.getFullYear();
        var   month=now.getMonth()+1;
        var   date=now.getDate();
        var   hour=now.getHours();
        var   minute=now.getMinutes();
        var   second=now.getSeconds();
        return   year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;
    }
</script>
</body>
</html>












